package com.chanyachting.emall.action.applicationLeter;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.chanyachting.emall.domain.Applicationleter;
import com.chanyachting.emall.domain.Educationhistory;
import com.chanyachting.emall.form.EducationhistoryForm;
import com.chanyachting.emall.service.ApplicationLeterService;
import com.chanyachting.emall.serviceImpl.ApplicationLeterServiceImpl;
import com.chanyachting.emall.util.RequestUtil;

public class AddEducationhistoryAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		
		EducationhistoryForm ehForm=(EducationhistoryForm)form;
		
		Educationhistory eh=new Educationhistory();
		
		BeanUtils.copyProperties(eh, ehForm);
		
		RequestUtil ru=new RequestUtil(request);
		
		if(ehForm.getAppId()!=0){
			
			Applicationleter al=new Applicationleter();
			
			al.setId(ehForm.getAppId());
			
			ApplicationLeterService alservice=new ApplicationLeterServiceImpl();
			
			boolean temp=alservice.addEducationhistory(al, eh);
			
			if(temp) ru.setSuccessMsg(); else ru.setFailMsg();
			
		}else{
			
			//如果没有求职信息id，保存教育背景到session 中
			//从sesinon 中获得已经保存过的工作历史对象集合
			List ehList=(List)ru.getSessionObject(ApplicationLeterService.EDUCATIONHISTORYLISTINSESSINO, new ArrayList());
			
			eh.setId(0);
			
			ehList.add(eh); //保存工作经历对象到集合中
			
			//将所有工作经历对象，保存在session 中
			ru.setSessionObject(ApplicationLeterService.EDUCATIONHISTORYLISTINSESSINO, ehList);
			
			ru.setSuccessMsg();
			
			
		}
		
		return mapping.findForward("");
	}
	
	
	

}
